Telegram Group & Telegram Channel
🧵 Как упростить отладку Python-скриптов с помощью breakpoint()

Привет! Сегодня хочу поделиться небольшим, но очень полезным трюком, который многие почему-то упускают — встроенная функция breakpoint().

С версии Python 3.7 и выше ты можешь просто вставить breakpoint() в нужное место кода, и он сразу остановится, запустив интерактивный отладчик. По умолчанию это pdb, но можно переопределить через переменную окружения PYTHONBREAKPOINT.

Пример:


def calculate(x, y):
result = x * y
breakpoint()
return result + 1

calculate(3, 5)


В момент вызова breakpoint() ты окажешься прямо в интерактивной сессии: можно смотреть переменные, шагать по коду и т.д.

🔥 Почему это удобно:

* Не нужно импортировать pdb вручную
* Работает в любом месте — в скриптах, Django-представлениях, Flask-хендлерах
* Легко отключается: запусти скрипт с PYTHONBREAKPOINT=0, и breakpoint() будет просто игнорироваться

Пользуетесь ли вы этой фичей в повседневной работе? Или все еще вставляете print()? 😄

Подписывайтесь на канал 👉@pythonofff



tg-me.com/pythonofff/2912
Create:
Last Update:

🧵 Как упростить отладку Python-скриптов с помощью breakpoint()

Привет! Сегодня хочу поделиться небольшим, но очень полезным трюком, который многие почему-то упускают — встроенная функция breakpoint().

С версии Python 3.7 и выше ты можешь просто вставить breakpoint() в нужное место кода, и он сразу остановится, запустив интерактивный отладчик. По умолчанию это pdb, но можно переопределить через переменную окружения PYTHONBREAKPOINT.

Пример:


def calculate(x, y):
result = x * y
breakpoint()
return result + 1

calculate(3, 5)


В момент вызова breakpoint() ты окажешься прямо в интерактивной сессии: можно смотреть переменные, шагать по коду и т.д.

🔥 Почему это удобно:

* Не нужно импортировать pdb вручную
* Работает в любом месте — в скриптах, Django-представлениях, Flask-хендлерах
* Легко отключается: запусти скрипт с PYTHONBREAKPOINT=0, и breakpoint() будет просто игнорироваться

Пользуетесь ли вы этой фичей в повседневной работе? Или все еще вставляете print()? 😄

Подписывайтесь на канал 👉@pythonofff

BY Python академия




Share with your friend now:
tg-me.com/pythonofff/2912

View MORE
Open in Telegram


Python академия Telegram | DID YOU KNOW?

Date: |

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

Export WhatsApp stickers to Telegram on iPhone

You can’t. What you can do, though, is use WhatsApp’s and Telegram’s web platforms to transfer stickers. It’s easy, but might take a while.Open WhatsApp in your browser, find a sticker you like in a chat, and right-click on it to save it as an image. The file won’t be a picture, though—it’s a webpage and will have a .webp extension. Don’t be scared, this is the way. Repeat this step to save as many stickers as you want.Then, open Telegram in your browser and go into your Saved messages chat. Just as you’d share a file with a friend, click the Share file button on the bottom left of the chat window (it looks like a dog-eared paper), and select the .webp files you downloaded. Click Open and you’ll see your stickers in your Saved messages chat. This is now your sticker depository. To use them, forward them as you would a message from one chat to the other: by clicking or long-pressing on the sticker, and then choosing Forward.

Python академия from it


Telegram Python академия
FROM USA